package sz.szsmk.citizencard.ui.activity;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
import android.view.View;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.Toast;

import com.chenenyu.router.annotation.Route;
import com.flyco.tablayout.SlidingTabLayout;
import com.flyco.tablayout.listener.OnTabSelectListener;
import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.ui.base.IBaseActivity;
import sz.szsmk.citizencard.ui.fragment.SimpleCardFragment;

import java.util.ArrayList;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/7/18 8:55
 * description:
 */
@Route("order")
public class UserOrderActivity extends IBaseActivity implements OnTabSelectListener {

    private final String[] mTitles = {
            "充值", "旅游", "商城", "文化消费", "旅游"
    };
    private ArrayList<Fragment> mFragments = new ArrayList<>();
    private SlidingTabLayout tabLayout;

    private MyPagerAdapter mAdapter;
    private ViewPager viewPager;
    private ImageView back;

    @Override
    protected int attachLayoutRes() {
        return R.layout.user_order_activity;
    }

    @Override
    protected void initInjector() {

    }

    @Override
    protected void initViews() {

        for (String title : mTitles) {
            mFragments.add(SimpleCardFragment.getInstance(title));
        }
        WebView wv_content = (WebView) findViewById(R.id.wv_content);

        tabLayout = (SlidingTabLayout) findViewById(R.id.tl_2);
        viewPager = (ViewPager) findViewById(R.id.vp);
        mAdapter = new MyPagerAdapter(getSupportFragmentManager());
        viewPager.setAdapter(mAdapter);
        tabLayout.setViewPager(viewPager);
        back = (ImageView) findViewById(R.id.back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        tabLayout.setOnTabSelectListener(this);
    }


    @Override
    protected void updateViews() {

    }

    @Override
    public void onTabSelect(int position) {
        if (position == 0) {
            Toast.makeText(this, position+"", Toast.LENGTH_SHORT).show();
        }
        if (position == 1) {

            Toast.makeText(this, position+"", Toast.LENGTH_SHORT).show();
        }
        if (position == 2) {

            Toast.makeText(this, position+"", Toast.LENGTH_SHORT).show();
        }
        if (position == 3) {

            Toast.makeText(this, position+"", Toast.LENGTH_SHORT).show();
        }
        if (position == 4) {

            Toast.makeText(this, position+"", Toast.LENGTH_SHORT).show();
        }

    }

    @Override
    public void onTabReselect(int position) {

    }

    private class MyPagerAdapter extends FragmentPagerAdapter {
        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles[position];
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }
    }
}
